﻿@model IEnumerable<DotNetUniLodz.Models.Article>
@{    
    DotNetUniLodz.Models.DotNetULEntities db = new DotNetUniLodz.Models.DotNetULEntities();
    ViewBag.Title = "Strona główna";
}

@if (Model != null)
{
    @Html.Partial("_MainArticle", Model)
}

<div id="Columns">
    <section id="News">
        @{
            var articles = db.Articles.OrderByDescending(a => a.Article_id).Where(a => !a.Article_isMainArticle).Take(9);
            foreach (var article in articles)
            {
                article.Article_text = System.Text.RegularExpressions.Regex.Replace(article.Article_text, "<[^>]*>", string.Empty);
            }         
        }

        @foreach (var item in articles)
        {
            <article>
                <header>
                    @Html.ActionLink(item.Article_title, "Details", "Articles", new { id = item.Article_id }, null)
                </header>
                <div>
                    @Html.Partial("_DisplayNewsInfo", item)
                    <p>
                        @{
            if (item.Article_text.Length > 160)
            {
                //@item.Article_text.Substring(0, 160) Write("...");
                            @Html.Raw(item.Article_text.Substring(0, 160) + "...")
            }
            else
            {
                // @item.Article_text
                            @Html.Raw(item.Article_text)
            }
                        }
                    </p>
                </div>
                <footer>
                    @{
            if (item.Event_id != null)
            {                    
@*<a href="@item.Event.Event_link" class="ArticleRegister">@item.Event.Event_name.Substring(0, item.Event.Event_name.Length > 20 ? 20 : item.Event.Event_name.Length) @if (item.Event.Event_name.Length > 20) { Write("..."); }</a>*@
                var eventName = item.Event.Event_name.Substring(0, item.Event.Event_name.Length > 20 ? 17 : item.Event.Event_name.Length);
                if (item.Event.Event_name.Length > 20) { eventName += "..."; }
                        @Html.ActionLink(eventName, "Details", "Events", new { id = item.Event.Event_id }, new { @class = "ArticleRegister" })
            }            
                    }
                    @Html.ActionLink("Więcej informacji", "Details", "Articles", new { id = item.Article_id }, new { @class = "ArticleMore" })
                </footer>
            </article>
        }
        @Html.ActionLink("Więcej aktualności", "Index", "Articles", null, new { @class = "ShowMoreArticles" })
    </section>
    @Html.Partial("_Tiles")

    @Html.Action("_Events")
</div>
<div class="CLear"></div>
